package socketmvc.core.processor.bean.optimizer.ret;

import socketmvc.core.context.IContext;
import socketmvc.core.packets.basic.IPacket;
import socketmvc.core.packets.basic.impl.JsonTextBody;
import socketmvc.core.processor.bean.ProcessorMethodReturn;

public abstract class DefAbstractRetOptimizer<R> extends ProcessorMethodReturn.ValOptimizer  {

    @SuppressWarnings("unchecked")
    @Override
    public IPacket value(IContext context, IPacket packet, Object returnVal) {
        String callback = packet.getResponseKey();
        JsonTextBody textBody = new JsonTextBody();
        textBody.setResponseKey(callback);
        textBody.setResponse(true);
        return doValue(context,packet,(R)returnVal,textBody);
    }


    public abstract IPacket doValue(IContext context, IPacket packet, R returnVal, JsonTextBody responseTextBody);
}
